package com.spring.demo8.eg4;

import org.junit.Test;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;

/**
 * @author vhans
 */
public class MergedBeanDefinitionTest {
    @Test
    public void test1() {
        DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
        XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader(factory);
        String location = "classpath:/xml/demo8/eg4Lesson.xml";
        xmlBeanDefinitionReader.loadBeanDefinitions(location);
        for (String beanName : factory.getBeanDefinitionNames()) {
            // 获取原始注册的beanDefinition信息
            BeanDefinition beanDefinition = factory.getBeanDefinition(beanName);
            // 获取合并之后的BeanDefinition信息，DefaultListableBeanFactory是AbstractBeanFactory的孙子类
            BeanDefinition mergedBeanDefinition = factory.getMergedBeanDefinition(beanName);

            System.out.println(beanName);
            System.out.println("  解析xml过程中注册的beanDefinition: " + beanDefinition);
            System.out.println("  beanDefinition的属性信息: " + beanDefinition.getPropertyValues());

            System.out.println("  合并之后得到的mergedBeanDefinition: " + mergedBeanDefinition);
            System.out.println("  mergedBeanDefinition的属性信息: " + mergedBeanDefinition.getPropertyValues());
        }
    }
}
